<template>
  <div class="container" ref="mainCon">
    <el-row>
      <!-- {{this.$store.state.activeMenuName}} -->
      <topTitle titleText="工程项目申报"></topTitle>
      <el-button
        class="commonBut saveBtn funComBut fr"
        v-show="hasDeclare && isShowAdd"
        icon="icon iconfont icontianjia"
        @click="addDeclare"
        style="position: absolute; right: 24px; top: 7px"
      >
        <span class="opetareText">新建申报</span></el-button
      >
    </el-row>
    <div class="mainCon">
      <el-row class="tipBar2">
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/declarePro.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>1.申报项目</div>
            <span class="fontCss">施工方申报项目</span>
          </div>
        </el-col>
        <el-col class="stepCss">
          <img src="../../../static/img/salary/stepLine.png" class="lineCss" />
        </el-col>
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/auditReport.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>2.等待审核</div>
            <span class="fontCss">等待当地监管部门审核申报内容</span>
          </div>
        </el-col>
        <el-col class="stepCss">
          <img src="../../../static/img/salary/stepLine.png" class="lineCss" />
        </el-col>
        <el-col class="hint">
          <div class="imgLabel">
            <img
              src="../../../static/img/declare/approved.png"
              class="picCss"
            />
          </div>
          <div class="hintCss">
            <div>
              3.审核通过
              <el-tooltip content="Top center" placement="top" effect="dark">
                <div slot="content">
                  审核驳回怎么办？根据监管部门驳回理由
                  <br />修改项目信息后重新申报即可
                </div>
                <i class="icon iconfont iconhuabanfuben"></i>
              </el-tooltip>
            </div>
            <el-tooltip
              content="Bottom center"
              placement="bottom"
              effect="dark"
            >
              <div slot="content">
                审核通过后企业可管理项目，项目经理
                <br />可使用手机号码注册账号管理项目
              </div>
              <span class="fontCss ellipsis"
                >审核通过后企业可管理项目,项目经理可使用手机号码注册账号管理项目</span
              >
            </el-tooltip>
          </div>
        </el-col>
      </el-row>
      <div v-show="hasDeclare">
        <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
          <el-form :inline="true" :model="filterField" ref="searchConditions">
            <el-col :lg="8" :xl="6">
              <el-form-item label="项目名称" class="row-padding-bottom">
                <el-input
                  v-model="filterField.projectName"
                  placeholder="请输入项目名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="申报日期" class="row-padding-bottom">
                <el-date-picker
                  v-model="date"
                  type="daterange"
                  unlink-panels
                  :picker-options="pickerOptions"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <template v-if="advanced">
              <el-col :lg="8" :xl="6">
                <el-form-item label="申报状态" class="row-padding-bottom">
                  <el-select
                    v-model="filterField.status"
                    filterable
                    placeholder="请选择"
                    clearable
                  >
                    <el-option
                      v-for="item in statusOptions"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <!-- <el-form-item>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="commonBtn"
              ></el-button>
            </el-form-item> -->
            </template>
            <el-col :lg="8" :xl="6">
              <el-form-item label="">
                <a
                  @click="toggleAdvanced"
                  style="margin-left: 40px; color: #409eff; cursor: pointer"
                  class="btnColor"
                >
                  {{ advanced ? '收起' : '展开' }}
                  <i
                    :class="
                      advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'
                    "
                  ></i>
                </a>
                <el-button
                  type="primary"
                  icon="icon iconfont iconchazhao1"
                  @click="searchList"
                  class="searchBtn"
                >
                  <span>搜索</span>
                </el-button>
              </el-form-item>
              <el-form-item>
                <exportBtn
                  :dataLen="tableList.length"
                  :filterField="filterField"
                  api="api-s/report/export_QY_PROJECT_AUDIT"
                ></exportBtn>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
        <div class="spacing"></div>
        <div
          ref="tableBox"
          :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
        >
          <el-table
            ref="tableBox1"
            :max-height="tableHeight"
            @sort-change="sortChange"
            :data="tableList"
            v-loading="loading"
            :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
            highlight-current-row
            stripe
            style="border: 1px solid #dfe6ec"
          >
            <el-table-column label="项目名称" width="230">
              <template slot-scope="scope">
                <copyText
                  :tableIndex="scope.$index"
                  :copyTextName="scope.row.projectName"
                  :columnName="'projectName'"
                ></copyText>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="address" label="项目地址" align="center" :formatter="formatTd"></el-table-column> -->
            <el-table-column label="项目地址" width="230">
              <template slot-scope="scope">
                <copyText
                  :tableIndex="scope.$index"
                  :copyTextName="scope.row.address"
                  :columnName="'address'"
                ></copyText>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="pcName" label="建设方" align="center" :formatter="formatTd"></el-table-column>
          <el-table-column prop="pbName" label="施工方" align="center" :formatter="formatTd"></el-table-column> -->
            <el-table-column label="建设方" width="230">
              <template slot-scope="scope">
                <copyText
                  :tableIndex="scope.$index"
                  :copyTextName="scope.row.pcName"
                  :columnName="'pcName'"
                ></copyText>
              </template>
            </el-table-column>
            <el-table-column label="施工方" width="230">
              <template slot-scope="scope">
                <copyText
                  :tableIndex="scope.$index"
                  :copyTextName="scope.row.pbName"
                  :columnName="'pbName'"
                ></copyText>
              </template>
            </el-table-column>
            <el-table-column
              prop="creatorName"
              label="申报创建"
              align="center"
              :formatter="formatTd"
              min-width="120"
            ></el-table-column>
            <el-table-column
              prop="applyDate"
              label="申报时间"
              sortable="custom"
              align="center"
              :formatter="dateForma"
              min-width="140"
            ></el-table-column>
            <el-table-column
              prop="statusDesc"
              label="申报状态"
              align="center"
              :formatter="formatTd"
              min-width="120"
            ></el-table-column>
            <!-- <el-table-column prop="reason" label="驳回原因" align="center" :formatter="formatTd"></el-table-column> -->
            <el-table-column label="驳回原因" width="230">
              <template slot-scope="scope">
                <copyText
                  :tableIndex="scope.$index"
                  :copyTextName="scope.row.reason"
                  :columnName="'reason'"
                ></copyText>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="left"
              :formatter="formatTd"
              width="220"
              fixed="right"
            >
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  v-if="isShowDetail"
                  @click="toDetail(scope.$index, scope.row)"
                  >查看详情</el-link
                >
                <el-link
                  type="primary"
                  v-if="scope.row.status == 'AUDIT'"
                  @click="cancelApply(scope.row)"
                  >取消申报</el-link
                >
                <el-link
                  type="primary"
                  v-if="scope.row.status == 'CANCEL'"
                  @click="reApply(scope.row)"
                  >重新申报</el-link
                >
              </template>
            </el-table-column>
            <!-- 表格数据为空时，页面显示 -->
            <div slot="empty" v-show="isShow">
              <emptyTable emptyText="暂无相关信息"></emptyTable>
            </div>
          </el-table>
          <!-- filterField为搜索条件 -->
          <!-- getTableList为获取子组件的数据 -->
          <Pagination
            ref="pagination"
            @getList="getTableList"
            :filterField="filterField"
            :requestUrl="requestUrl"
          ></Pagination>
        </div>
      </div>
      <div class="content" v-show="!hasDeclare">
        <div>
          <i
            class="el-icon-location-outline"
            style="font-size: 150px; color: #c3c3c3"
          ></i>
        </div>
        <div style="color: #c3c3c3; margin-top: 10px; margin-bottom: 10px">
          暂无项目申报记录
        </div>

        <el-button
          class="commonBut saveBtn funComBut"
          icon="icon iconfont icontianjia"
          @click="addDeclare"
        >
          <span class="opetareText">新建申报</span></el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
export default {
  name: 'projectDeclareList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '工程项目申报',
      advanced: false,
      titleExplain: '',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
      },
      statusOptions: [], //申报状态
      //表格数据
      tableList: [],
      requestUrl: 'api-p/projectapplication/expand/company/list',
      date: [],
      //搜索条件
      filterField: {
        projectName: '', //项目名称
        applyStartDate: '',
        applyEndDate: '',
        status: '', //申报状态
      },
      isShow: false, //列表加载
      loading: true,
      hasDeclare: true,
      isSearch: false,
      isQy: true,
      active: -1,
      isShowAdd: '',
      isShowDetail: '',
    }
  },
  created() {
    if (this.$route.query.type == 'projectDeclareList') {
      this.$store.state.activeMenu = '/home/project/projectDeclareList'
    }
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    // this.isQy = localStorage.getItem('loginType') == "QY" ? true : false ;
    this.getStatus() //获取申报状态
    this.isShowAdd =
      this.$store.state.buttonLimitsArr.indexOf('projectDeclareList:add') >
        -1 ||
      this.$store.state.buttonLimitsArr.indexOf('projectDeclareListSGF:add') >
        -1
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('projectDeclareList:detail') >
        -1 ||
      this.$store.state.buttonLimitsArr.indexOf(
        'projectDeclareListSGF:detail'
      ) > -1
  },
  computed: {
    mianConTop: function () {
      return this.isQy ? '270px' : '195px'
    },
  },
  // activated(){
  //    this.$nextTick(function() {
  //     this.$refs.pagination.getTableListData();
  //   });
  // },
  methods: {
    //撤销申报
    cancelApply(item) {
      this.$confirm('是否确认取消申报? 取消后可重新提交。', '提示', {
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning',
      })
        .then(() => {
          this.axios
            .post('api-p/projectapplication/expand/cancellation', {
              id: item.id,
            })
            .then((res) => {
              if (!res.data.hasError) {
                this.$message({
                  message: '项目申报已取消',
                  type: 'success',
                })
                this.searchList()
              } else {
                this.$message({
                  message: response.data.errorMsg,
                  type: 'error',
                })
              }
            })
        })
        .catch(() => {
          // this.$message.error("删除失败");
        })
    },
    //重新申报
    reApply(row) {
      this.$router.push({
        path: '/home/monitorProjectManagement/newProjectApplication',
        name: 'newProjectApplication',
        query: {
          id: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/project/projectDeclareList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.isSearch) {
        this.hasDeclare = true
        this.isShow = this.tableList.length <= 0
      } else {
        this.hasDeclare = this.tableList.length > 0 ? true : false
      }
      // if (this.tableList.length < 1) {
      //   this.isShow = true;
      //   // this.toDeclareListEmpty();
      // }
    },
    getStatus() {
      this.axios({
        method: 'post',
        url: 'api-p/projectapplication/expand/status',
        data: {},
      })
        .then((response) => {
          this.statusOptions = response.data.result
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 3000,
            message: '获取申报状态数据失败',
            type: 'error',
          })
        })
    },
    // 搜索
    searchList() {
      if (this.date) {
        this.filterField.applyStartDate = this.date[0]
        this.filterField.applyEndDate = this.date[1]
      } else {
        this.filterField.applyStartDate = ''
        this.filterField.applyEndDate = ''
      }
      this.isSearch = true
      this.loading = true
      this.$refs.pagination.getTableListData()
    },
    //跳转详情
    toDetail(index, row) {
      this.$router.push({
        path: '/home/project/projectDeclareDetail',
        name: 'projectDeclareDetail',
        query: {
          id: row.id,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/project/projectDeclareList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    toDeclareListEmpty() {
      this.$router.push({
        path: '/home/project/projectDeclareListEmpty',
        name: 'projectDeclareListEmpty',
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/project/projectDeclareList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    addDeclare() {
      this.$router.push('/home/monitorProjectManagement/newProjectApplication')
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/project/projectDeclareList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    dateForma: function (row, column) {
      const daterc = row[column.property]
      if (daterc != null) {
        // const dateMat= new Date(parseInt(daterc.replace("/Date(", "").replace(")/", ""), 10));
        // const year = dateMat.getFullYear();
        // const month = dateMat.getMonth() + 1;
        // const day = dateMat.getDate();
        // const hh = dateMat.getHours();
        // const mm = dateMat.getMinutes();
        // const ss = dateMat.getSeconds();
        // const timeFormat= year + "/" + month + "/" + day + " " + hh + ":" + mm + ":" + ss;
        return daterc
      } else {
        return '--'
      }
    },
  },
}
</script>

<style scoped lang="less">
.mainCon {
  padding-top: 3px;
}
.topTitle {
  height: 67px;
  background-color: #e4ebf1;
  padding-left: 24px;
  line-height: 67px;
  h2 {
    font-size: 18px;
    color: #333333;
    font-weight: bold;
    display: inline-block;
  }
  .saveBtn {
    margin-right: 24px;
    margin-top: 15.5px;
  }
}
.content {
  text-align: center;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.tipBar2 {
  height: 88px;
  margin: 35px 20px;
}
.hint {
  float: left;
  display: block;
  width: 24%;
  padding-left: 5%;
}
.imgLabel {
  display: inline-block;
  /* width: 80px; */
  float: left;
}
.picCss {
  /* height: 80px;
  width: 80px;
  font-size: 88px; */
  color: #d0d0d8;
}
.lineCss {
  width: 100%;
  height: 8px;
  margin-top: 40px;
}
.stepCss {
  float: left;
  display: block;
  width: 12%;
}
.hintCss {
  display: block;
  margin-left: 85px;
  margin-top: 15px;
}
.fontCss {
  font-size: 14px;
  color: #666;
  display: block;
  /* text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical; */
}
.noRule {
  text-align: center;
  img {
    margin: 60px 0;
  }
}
@media screen and (min-width: 1280px) and (max-width: 1366px) {
  .searchInputWidth /deep/ .el-form-item__label {
    width: 70px;
  }
}
@import '../../../static/css/filterArea.less';
</style>
